package com.javen.mdc.springbootmdc.controller;

import com.javen.mdc.springbootmdc.service.TestService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import static java.util.stream.Collectors.toList;

/**
 * @Description: com.javen.mdc.springbootmdc.controller
 * @Author: tujw@netinnet.cn
 * @Date: 2022/12/28 10:25
 */
@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {

    @Autowired
    private TestService testService;

    @GetMapping("/testmdc")
    public void mdcTest() {
        log.info("TestController");
        testService.testMdc();
    }

    @PostMapping("/testform")
    public void testform(Integer formId) {
        log.info("formId值={}", formId);
    }

    @Data
    static class BeanA {

        private String name;

//        public String getName() {
//            return name;
//        }
//
//        public void setName(String name) {
//            this.name = name;
//        }
    }

    public static void main(String[] args) {
        List<TestController.BeanA> beanAList = new ArrayList<>();
        beanAList.add(new TestController.BeanA());
        beanAList.add(new TestController.BeanA());
        //加了@Data注解，组合带上了@EqualsAndHashCode（比较所有非静态变量和非 transient 的变量），所以即使list中两个对象都是new出来的distinct的时候也会去重一个
        List<TestController.BeanA> beanAList2 = beanAList.stream().distinct().collect(toList());
        beanAList2.stream().max(Comparator.comparingInt(a -> a.getName().length()));
        System.out.println("结束");
    }

}
